<%@page import="com.crm.entity.Clientdet,com.crm.entity.Opportunity,com.crm.util.Constants,java.util.List,com.crm.entity.Parts,com.crm.entity.Currency,com.crm.entity.Variables,com.crm.entity.Quotation,com.crm.entity.Business,com.crm.beans.NewQuotVO" %>
<% String srname=(String)request.getAttribute("sourcename");
String supname=(String)request.getAttribute("suppname");
String unitprice=(String)request.getAttribute("uprice");
String terms=(String)request.getAttribute("tnc");
List<Quotation> prequot =(List<Quotation>)request.getAttribute("listquot");
List<Parts> parts =(List<Parts>)request.getAttribute("partlist");
List<NewQuotVO> quotlist =(List<NewQuotVO>)request.getAttribute("newquotlist");
String QuotNo=(String)request.getAttribute("genQuotNo");
Business bus=(Business)request.getAttribute("business");
Variables v=(Variables)request.getAttribute("variables");
Currency currency=(Currency)request.getAttribute("currency");
String quotCurr=request.getAttribute("enqCurrType").toString();
System.out.println("the list of parts"+parts);
Opportunity op=(Opportunity)request.getAttribute("opportunity");
Clientdet clientdet =(Clientdet)request.getAttribute("client");
%>
<script type="text/javascript" src="<%=application.getContextPath()%>/js/colResizable-1.3.min.js"></script>	
<script language="JavaScript">
$(function(){
	  $("#quotPartTable").colResizable();
	});
function setRupeeAsses(rno,up,edvalue) {
	var up= document.getElementById('unitid'+rno).value;
	//alert(up);
	var edval=10.3;
	var excessDuty=parseFloat(edval*up/100).toFixed(2);
	//alert(excessDuty);
	 document.getElementById('assesid'+rno).value=parseFloat(up)+parseFloat(excessDuty);
}
function setRupeeTot(rno){	
	var excessDuty=document.getElementById('assesid'+rno).value;
	var cst=document.getElementById('bcdid'+rno).value;
	var cstVal;
	var fright;
	var subtot;
	if(cst=="5%LOC"){
		var up= document.getElementById('unitid'+rno).value;
		alert(up);
		fright=document.getElementById('frightid'+rno).value;
		alert(fright);
		cstVal=(((parseFloat(up)+parseFloat(fright))*5)/100);
		alert(cstVal);
		subtot=parseFloat(up)+parseFloat(cstVal)+parseFloat(fright);
		alert(subtot);
		document.getElementById('totid'+rno).value=parseFloat(subtot).toFixed(2);
	}else{
		 cstVal=(parseFloat(excessDuty)*parseFloat(cst))/100;
		fright=document.getElementById('frightid'+rno).value;
		subtot=parseFloat(excessDuty)+parseFloat(cstVal)+parseFloat(fright);
		document.getElementById('totid'+rno).value=parseFloat(subtot).toFixed(2);
	}
	
	 
}function setqPrice(rno,currencyVal){
	var subtot=document.getElementById('totid'+rno).value;
	  var margin=document.getElementById('marginid'+rno).value;
	  var marginVal=(parseFloat(subtot)*parseFloat(margin))/100;
	 var unitPrice=subtot+marginVal;
	   document.getElementById('unitprcie'+rno).value=parseFloat(unitPrice).toFixed(0);
	  }
  function setAsses(rno,currencyVal) {
		  
	  
	 var todays_INR=currencyVal;
	/*   alert("Todays INR IS:"+todays_INR.toFixed(2));  */
	 
	  var qty =document.getElementById('reqtyqid'+rno).value;
	   /* alert("Qty Is:"+qty);  */
	  
	  var  unitval=document.getElementById('unitid'+rno).value;
	   /* alert("Unit Val Is:"+unitval); */ 
	  
	  var  individual_fright =document.getElementById('frightid'+rno).value;
	   /* alert("Fright Val Is:"+fright);  */
	  
	 /*  var individual_fright=parseFloat(fright/qty); */
	   /* alert("Individual Fright Is:"+individual_fright); */ 
	  
	  var insurance=parseFloat((unitval*(<%=v.getInsurancePercent()%>))/100);
	   /* alert("Insurance Is:"+insurance); 
		alert("Unit Value Is:"+unitval+"Fright:"+individual_fright+"\n Insurance :"+insurance+"\n "); */
	  var ass_val=parseFloat(parseFloat(unitval)+parseFloat(individual_fright)+parseFloat(insurance)).toFixed(2);
	   /* alert("Assessable Val Is:"+ass_val);  */
		
	 var aval=(ass_val*todays_INR).toFixed(2);	
	  document.getElementById('assesid'+rno).value=aval;
	
  }
  function setTot(rno,currencyVal){
	 
	  var todays_INR=currencyVal;
	  var cvdPercent=<%=v.getCvdPercent()%>;
	   /* alert("CVD Percent Is:"+cvdPercent); */ 
	  
	  var cessPercent=<%=v.getCessPercent()%>;
	  /*  alert("Cess Percent Percent Is:"+cessPercent); */ 
	  
	  var edcessPercent=<%=v.getEdCessPercent()%>;
	   /* alert("ED Percent Is:"+edcessPercent);  */
	  
	  var sadPercent=<%=v.getSadPercent()%>;
	   /* alert("SAD Percent Is:"+sadPercent);  */
	  
	  var qty =document.getElementById('reqtyqid'+rno).value;
	  /* alert("Req Qty Is:"+qty);  */
	  
	  var  unitval=document.getElementById('unitid'+rno).value;
	   /* alert("Unit Val Is:"+unitval);  */
	  
	  var fright =document.getElementById('frightid'+rno).value;
	   /* alert("Fright Val Is:"+fright);  */
	  
		
		var insurance=parseFloat((unitval*<%=v.getInsurancePercent()%>)/100);
		 /* alert("Insurance Is:"+insurance);  */
		
		var ass_val=document.getElementById('assesid'+rno).value;
		 /* alert("Assessable Val Is:"+ass_val);  */
		
		 var t=parseFloat((ass_val)/100);
		var handling_charge=parseFloat(t)+parseFloat(ass_val);
		 /* alert("Handling Charge Is:"+handling_charge); */ 
		
		 var bcdPercent=document.getElementById('bcdid'+rno).value;
		  /* alert("BCD Percent Is:"+bcdPercent);  */
		
		var bcd=parseFloat((bcdPercent/100)*handling_charge);
		 /* alert("BCD Value Is:"+bcd);  */
			
		
		
		
		var temp1=parseFloat(bcd+handling_charge);
		 /* alert("temp 1 val Is:"+temp1);  */
		var temp2=parseFloat(cvdPercent/100);
		 /* alert("temp 2 val Is:"+temp2);  */
		var temp3=parseFloat(temp2*temp1);
		 /* alert("temp 3 val Is:"+temp3);  */
		var cvd=temp3;
		 /* alert("CVD Val Is:"+cvd);  */
	 
		var cess=parseFloat(cvd*(cessPercent/100));
		 /* alert("CESS Val Is:"+cess);  */
		
		
		var tot_tax=parseFloat(bcd+cvd+cess);
		 /* alert("Total Tax  Is:"+tot_tax);  */
		
		var ed_cess=parseFloat(tot_tax*(edcessPercent/100));
		 /* alert("EDCESS Val Is:"+ed_cess);  */
		
		var afterEDCess=parseFloat(tot_tax+ed_cess);
		 /* alert("after EDCESS Val Is:"+afterEDCess); */ 
		
		var sad=parseFloat(afterEDCess*(sadPercent/100));
		 /* alert("SAD Val Is:"+sad);  */
		
		
		var customs_duty=parseFloat(sad+afterEDCess);
		 /* alert("Customs Duty Is:"+customs_duty); */ 
		
		var subtot=parseFloat(handling_charge+customs_duty).toFixed(2);
		 /* alert("Sub Total Val Is:"+subtot);  */
		
	   document.getElementById('totid'+rno).value=subtot;
	
	  }
  function setqPrice(rno,currencyVal){
	 
	  var todays_INR=currencyVal;
	<%--   var vatPercent=<%=v.getVatPercent()%>; --%>
	  var qty=document.getElementById('reqtyqid'+rno).value;
	   /* alert("Quantity Is:"+qty);  */
	  
	 var tot= document.getElementById('totid'+rno).value;
	  /* alert("Total Value is:"+tot);  */
	 
	 var  marginPercent=document.getElementById('marginid'+rno).value;
	 /* alert("margin percent Is:"+marginPercent); */ 
	
	  var totVal=tot;
	  /* alert("Total Value Is:"+totVal);  */
	 
	  var marginValue=parseFloat((marginPercent*totVal/100));
	   /* alert("Margin value Is:"+marginValue); */ 
	  
	  var netTot=parseFloat(totVal)+parseFloat(marginValue);
	   /* alert("Net Total Is:"+netTot);  */
	  
	 /*  var  vat=parseFloat(netTot*(vatPercent/100)); */
	   /* alert("VAT Value Is:"+vat);  */
	   var grandTot=parseFloat(parseFloat(netTot)/* +parseFloat(vat) */).toFixed(2);
	   //alert(grandTot);
	   var totPrice=0;
	   var curr='<%=quotCurr%>';
	  if(curr=='<%=Constants.ST_CUR_DOLLAR%>')
	  {
		  totPrice=parseFloat(grandTot/(<%=currency.getDollar()%>)).toFixed(2);
		  //alert(totPrice);
	  }else{
		  totPrice=grandTot;
	  }
	  
	   /* alert("Grand Total Value Is:"+grandTot); */ 
	  document.getElementById('unitprcie'+rno).value=totPrice;
	 
	
	  }
  function setQuotPrice(rno){
	  var unitPrice=  document.getElementById('unitprcie'+rno).value;
	  var qty=  document.getElementById('reqtyqid'+rno).value;
	  var qprice=parseFloat(unitPrice*qty).toFixed(2);
	   document.getElementById('qpriceid'+rno).value=parseFloat(qprice).toFixed(0);
  }
</script>

<div class="boxIFS">
  <table width="100%" >
  <tr>  <td>
  Quotation Currency Is:<%=quotCurr%></td>
  <td align="left" width="50%"> 
 Quotation No .&nbsp; <input name="quotno" type="text" class="form"  style=" width:300px ; color: blue;" id="quotno" value="<%=QuotNo %>" />
</td>
<td align="center" width="50%">
<div id="historyDiv" align="center"  style="color:#F6871F ; font-weight: bold; font-size:16px" title="Click Here To View All Quotations For This Enquiery">Previous Quotation's History</div>
<table style="display:none ; width :350px;"  id="tableId"><tr><td>&nbsp;</td></tr>
<%if(prequot.size()!=0&&prequot!=null){
	for(int i=0;i<prequot.size();i++)
	{%>
<tr><td align="center"><a  class="linkclass" href="#"  onclick="open_new_window('<%=application.getContextPath() %>/newquot/get_history.do?quotid=<%=prequot.get(i).getQuotno()%>')" ><%=prequot.get(i).getQuotno()%></a></td></tr>
<%}
}%>
</table>




<script>

function open_new_window(url) {
	  window.open(url,"some_name","width=500,height=300,left=200,top=10");
	}

    function previewUrl(url,target){
        //use timeout coz mousehover fires several times
        clearTimeout(window.ht);
        window.ht = setTimeout(function(){
            var div = document.getElementById(target);
            div.innerHTML = '<iframe style="width:100%;height:100%;" frameborder="0" src="' + url + '" />';
        },20);      
    }   
</script>

</td>
</tr>

</table>
		<table>
		<tr>
<td align="left"><input type="checkbox" name="cdec" align="left"/>CDEC Required</td>
<td>&nbsp;</td>
</tr>
		</table>
		<%
		if(op.getWarranty()!=null){
		if(op.getWarranty()==true){
			out.println("This Quotation Has Warranty");
		}
		}
		%>
        <table id="quotPartTable" width="100%" border="0" cellpadding="4" cellspacing="1" bgcolor="#C5E4EB">
        <tr>
         
            <td  align="center" valign="middle" background="<%=application.getContextPath() %>/images/table-box.jpg"  style="background-repeat:repeat-x">S.No </td>
            <td  align="center" valign="middle" background="<%=application.getContextPath() %>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">Part No.</td>
            <td  align="center" valign="middle" background="<%=application.getContextPath() %>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF"> Make</td>
            <td  align="center" valign="middle" background="<%=application.getContextPath() %>/images/table-box.jpg"  style="background-repeat:repeat-x bgcolor="#FFFFFF">Description</td>
            <td  align="center" valign="middle" background="<%=application.getContextPath() %>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">Required</td>
            <td  align="center" valign="middle" background="<%=application.getContextPath() %>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">Source</td>
            <td  align="center" valign="middle" background="<%=application.getContextPath() %>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">Supplier</td>
            <td  align="center" valign="middle" background="<%=application.getContextPath() %>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">Unit Value</td>
            <td  align="center" valign="middle" background="<%=application.getContextPath() %>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">Fright</td>
            <td  align="center" valign="middle" background="<%=application.getContextPath() %>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">Assesable</td>
            <td  align="center" valign="middle" background="<%=application.getContextPath() %>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">BCD/CST</td>
            <td  align="center" valign="middle" background="<%=application.getContextPath() %>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">Sub Total</td>
            <td  align="center" valign="middle" background="<%=application.getContextPath() %>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">Margin</td>
            <td  align="center" valign="middle" background="<%=application.getContextPath() %>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">UnitPrice</td>
            <td  align="center" valign="middle" background="<%=application.getContextPath() %>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">QuotePrice</td>
            <td  align="center" valign="middle" background="<%=application.getContextPath() %>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">Delivery</td>
          </tr>
          <%
			for(int i=0;i<quotlist.size();i++){ %>
          <tr>
          
            <td align="center" bgcolor="#FFFFFF"><%=i+1 %></td>
           <%
           String bgcolor=null;
           float curr=quotlist.get(i).getCurrency();
           	if(curr==1 || curr==1.0){
           		bgcolor="#008000";
           	}else{
       
           bgcolor="#FFFFFF";
           } %>
            <td align="left" valign="top" bgcolor="<%=bgcolor%>"><input name="partid<%=i+1%>" type="hidden"  size="5" value="<%=quotlist.get(i).getPartId() %>" /><input name="partno<%=i+1%>" type="text"  class="part" size="5" value="<%=quotlist.get(i).getPartNo() %>" /></td>
            <td align="left" valign="top" bgcolor="#FFFFFF"><input name="make<%=i+1 %>" type="text" size="5"   value="<%=quotlist.get(i).getMake()%>" /></td>
            <td align="left" valign="top" bgcolor="#FFFFFF"><input name="desc<%=i+1 %>" type="text" size="5" value="<%=quotlist.get(i).getDescription()%>"/></td>
            <td align="left" valign="top" bgcolor="#FFFFFF"><input name="required<%=i+1 %>" type="text" id="reqtyqid<%=i+1 %>" size="5" value="<%=quotlist.get(i).getReqQty()%>" /></td>
            <td align="left" valign="top" bgcolor="#FFFFFF"><input name="source<%=i+1 %>" type="text"  size="5" value="<%=quotlist.get(i).getSourceName()%>"/></td>
            <td align="left" valign="top" bgcolor="#FFFFFF"><input name="supplier<%=i+1 %>" type="text" size="5"  value="<%=quotlist.get(i).getSuppName()%>"/></td>
            <td align="left" valign="top" bgcolor="#FFFFFF"><input name="uvalue<%=i+1 %>" id="unitid<%=i+1 %>" type="text" size="5" value="<%=quotlist.get(i).getUnitprice()%>"/></td>
            <td align="left" valign="top" bgcolor="#FFFFFF"><input name="fright<%=i+1 %>"  id="frightid<%=i+1 %>" type="text" size="5"  value="" onblur=
           "<%
            if(curr==1 || curr==1.0){
            %>
            setRupeeAsses(<%=i+1 %>)
            <%}else{%>
            setAsses(<%=i+1 %>,<%=quotlist.get(i).getCurrency()%>)
            <% }%>";
            /></td>
            <td align="left" valign="top" bgcolor="#FFFFFF"><input name="assesable<%=i+1 %>" id="assesid<%=i+1%>" type="text" size="5" value=""/></td>
            <%
            if(curr==1 || curr==1.0){
            %>
            <td align="left" valign="top" bgcolor="#FFFFFF"><select  name="bcd<%=i+1 %>" id="bcdid<%=i+1 %>" onblur="setRupeeTot(<%=i+1 %>);"><option value="2">2</option><option value="5">5</option><option value="14.5">14.5</option><option value="5%LOC">5%VAT(Local)</option></select></td>
            <%	}else{ %>
            <td align="left" valign="top" bgcolor="#FFFFFF"><select  name="bcd<%=i+1 %>" id="bcdid<%=i+1 %>" onblur="setTot(<%=i+1 %>,<%=quotlist.get(i).getCurrency()%>);"><option value="0">0</option><option value="7.5">7.5</option><option value="10">10</option></select></td>
            <%  
            }  %>
            <td align="left" valign="top" bgcolor="#FFFFFF"><input name="stot<%=i+1 %>" type="text"  id="totid<%=i+1 %>" size="5" value="" /></td>
            <td align="left" valign="top" bgcolor="#FFFFFF"><input name="margin<%=i+1 %>" type="text" id="marginid<%=i+1 %>" size="5" value="" onblur="setqPrice(<%=i+1 %>,<%=quotlist.get(i).getCurrency()%>);"/></td>
           <td align="left" valign="top" bgcolor="#FFFFFF"><input name="unitprice<%=i+1 %>" type="text" id="unitprcie<%=i+1 %>" size="5" value="" onblur="javascript:return setQuotPrice(<%=i+1 %>)"/></td>
            <td align="left" valign="top" bgcolor="#FFFFFF"><input name="quotprice<%=i+1 %>" type="text" id="qpriceid<%=i+1 %>" size="5" value="" /></td>
             <td align="left" valign="top" bgcolor="#FFFFFF"><input name="delivery<%=i+1 %>"  type="text" size="5" value=""/></td>
          </tr>
          <input type="hidden" id="rowcountid" name="rowcount" value="<%=quotlist.size() %>"/>
         <%} %>
            
        </table>
   		<div>
   		Green is for Rupee Calculation
   		</div>
      <div id="terms" style="display: none;" class="box2">
       <textarea rows="10" cols="60" name="termsAndConditions"><%=bus.getTandc() %></textarea>
       </div> 
	    <div class="buttton-main">
<table>
<tr><td>&nbsp;</td></tr>
<tr><td align="right"> <input   type="hidden" value="0" id="tc"/>
 <input  class="button" type="button" value="Terms and Conditions" id="tAndCButton"/>
	    <input  class="button" type="submit" value="Generate Quote" onclick=" javascript :return processFormData();" /></td></tr></table>
	   
	   
	    </div>
	    </div>
	  
      <script type="text/javascript">
      $("#tAndCButton").click(function(){
    	  $("#terms").toggle();
    	  $("#tc").val(1);
      });
      $("#historyDiv").click(function(){
    	  $("#tableId").toggle();
      });
 
      function alertTerms(){
	      var x;
	      var r=confirm("Please Check Terms And Conditions");
	      if (r==true){
	 	     return true;
	        } else{
	       return false;
	        }
	      }
      
      $(function(){
 		 var client="<%=clientdet.getOrganisation()%>";
 		 var cldiv="<%=clientdet.getDivision()%>";
 		 var cluser="<%=request.getAttribute("user")%>";
 		 $("#enqclient").html("Client Name Is:<span class='cliendet'>"+client +
 		"</span>   &nbsp;&nbsp;&nbsp;&nbsp;  Client Division Is:<span class='cliendet'>"+cldiv+
 		 "</span>    &nbsp;&nbsp;&nbsp;&nbsp;    Client User Is:<span class='cliendet'>"+cluser+"</span>");
 		 $("#enqclient").show();
 	 });
      </script>
   